clear all
set more off
set scheme s2color
cd ""

use "sample.dta", clear

****************
* Subfigure (1)
****************

* Generate time-to-event dummies

tab rel_time, gen(rel_w)

forvalue i = 1/31 {
local j = `i' - 11
label var rel_w`i' "`j'"
}

qui: reghdfe bdindexS7_std rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store bdindexS7_std

#delimit ;
coefplot bdindexS7_std, 
         vertical recast(scatter) keep(rel_w*) omitted
         order(rel_w1 rel_w2 rel_w3 rel_w4 rel_w5 rel_w6 rel_w7 rel_w8 rel_w9 rel_w10
               rel_w11 rel_w12 rel_w13 rel_w14 rel_w15 rel_w16 rel_w17 rel_w18 rel_w19 rel_w20 
               rel_w21 rel_w22 rel_w23 rel_w24 rel_w25 rel_w26 rel_w27 rel_w28 rel_w29 rel_w30 rel_w31)
         msymbol(Oh) mcolor(gs5) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(gs5))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0, lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash)) yscale(range(-0.225 0.6))
         ylabel(-0.2(0.2)0.6, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr

****************
* Subfigure (2)
****************

qui: reghdfe bdindexS7_std rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp if faction == 1, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store bdindexS7_std_f

qui: reghdfe bdindexS7_std rel_w1-rel_w9 rel_w11-rel_w31 rel_w10 wdsp temp prcp if faction == 0, absorb(i.city_code i.time i.prov_code#c.time) cluster(time)
est store bdindexS7_std_nf

#delimit ;
coefplot (bdindexS7_std_f,  msymbol(Oh) mcolor(green)  pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(green)))
         (bdindexS7_std_nf, msymbol(Th) mcolor(orange) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(*0.9))), 
         vertical recast(scatter) keep(rel_w*) omitted
         order(rel_w1 rel_w2 rel_w3 rel_w4 rel_w5 rel_w6 rel_w7 rel_w8 rel_w9 rel_w10
               rel_w11 rel_w12 rel_w13 rel_w14 rel_w15 rel_w16 rel_w17 rel_w18 rel_w19 rel_w20 
               rel_w21 rel_w22 rel_w23 rel_w24 rel_w25 rel_w26 rel_w27 rel_w28 rel_w29 rel_w30 rel_w31)
         xtitle("Relative days to Community Stringent Measures") xlabel(, valuelabel labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash)) yscale(range(-0.225 0.6))
         ylabel(-0.2(0.2)0.6, labsize(small) tlength(0.8) grid glwidth(vthin) nogextend)
         legend(label(2 "With informal tie") label(4 "Without informal tie") position(11) ring(0) col(1))
         graphregion(fcolor(white) color(white) icolor(white) margin(small)) plotregion(margin(vsmall));
#delimit cr
